<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>注册用户案例</title>
</head>

<body>
  <button class="reg-btn">注册用户</button>
  <script src="http://cdn.jsdelivr.net/npm/axios@0.21.1/dist/axios.min.js">
  </script>
  <script>
    document.querySelector('.reg-btn').addEventListener('click', e => {
      const xhr = new XMLHttpRequest()
      xhr.open('post', 'http://hmajax.itheima.net/api/register')
      xhr.addEventListener('loadend', () => {
        console.log(xhr.response)
      })
      xhr.setRequestHeader('Content-Type', 'application/json')
      const data = {
        username: 'admin',
        password: '123456',
      }
      const str = JSON.stringify(data)
      xhr.send(str)

    })

  </script>
</body>

</html>